package com.dc.bobaoge.project.v2.to.v3.business.core.method.user;

import com.dc.bobaoge.project.base.core.old.mapper.OldCoreUserMapper;
import com.dc.bobaoge.project.base.core.util.WalletUtil;
import com.own.business.sync.trigger.base.entity.SyncTrigger;
import com.own.business.sync.trigger.base.method.ResolveMethod;
import com.own.component.common.exception.BusinessSimpleException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * UserUpdatePayPasswordResolveMethod
 *
 * @author chenxueli
 * @date 2024-01-28 20:42:52
 */
@Slf4j
@Component
public class UserUpdatePayPasswordResolveMethod implements ResolveMethod {

    @Resource
    private OldCoreUserMapper oldCoreUserMapper;

    @Resource
    private WalletUtil walletUtil;

    /**
     * 修改的处理方法
     *
     * @param trigger 日志信息
     */
    @Override
    public void update(SyncTrigger trigger) {
        // 查询用户信息是否存在
        var oldCoreUser = oldCoreUserMapper.selectById(trigger.getTargetId());
        if (oldCoreUser == null) {
            throw new BusinessSimpleException("用户信息不存在");
        }
        // 查询钱包信息
        if (StringUtils.isBlank(oldCoreUser.getUserPayPwd())) {
            return;
        }
        // 设置钱包密码
        walletUtil.updatePassword(oldCoreUser.getUserId(), oldCoreUser.getUserPayPwd());
    }

    /**
     * 名称信息
     *
     * @return 名称
     */
    @Override
    public String name() {
        return "user_pay_password";
    }

}
